<?php
namespace app\admin\controller;
use think\console\Input;

use think\Request;

use think\Controller;
use think\Db;
class Integral extends Controller
{
   public function integral()
   {
   	$list=Db::name("jf_integral")
   	        ->order('in_number asc')
   	        ->paginate(2);
            
            $page = $list->render();

            $this->assign('list',$list);
            $this->assign('page', $page);
      return $this->fetch();

   }
   public function jf_add()
   {
   	  $request=Request::instance();
   	  if($request->has('sub','post'))
   	  {
   	     $in_number=$request->post('in_number');
   	     $in_health=$request->post('in_health');
   	     $in_study=$request->post('in_study');
   	     $in_active=$request->post('in_active');
   	     $in_time=$request->post('in_time');
   	     $in_log=$request->post('in_log');
   	     $data=[
   	           'in_number'=>$in_number,
   	           'in_health'=>$in_health,
   	           'in_study'=>$in_study,
   	           'in_active'=>$in_active,
   	           'in_time'=>$in_time,	   	       
	   	       'in_log'=>$in_log,
	   	       
   	     ];
   	   $result=Db::table('jf_integral')->insert($data);
   	   if($result)
   	   {
   	      $this->success('新增成功','Integral/integral');
   	   }
   	   else 
   	   {
   	      $this->error('新增失败');
   	   }
   	  }
   	  else 
   	  {
   	     $in_id=input('?param.in_id');
   	     $jf_integral=Db::table('jf_integral')->where('in_id',$in_id)->find();
   	     return $this->fetch('jf_add',[
   	                             'jf_integral'=>$jf_integral
   	         ]);
   	  }
      //return $this->fetch(); 
   }
   public function jf_update()
   {
    
   	$request=Request::instance();
  	if ($request->has("sub","post"))
  	{
	     $in_id=$request->param("in_id");
	     $in_number=$request->post('in_number');
   	     $in_health=$request->post('in_health');
   	     $in_study=$request->post('in_study');
   	     $in_active=$request->post('in_active');
   	     $in_time=$request->post('in_time');
   	     $in_log=$request->post('in_log');
	  	 $data=[
	  	       'in_id'=>$in_id,
   	           'in_number'=>$in_number,
   	           'in_health'=>$in_health,
   	           'in_study'=>$in_study,
   	           'in_active'=>$in_active,
	  	       'in_time'=>$in_time,	   	       
	   	       'in_log'=>$in_log,
	   	        	           
   	      ]; 	  	    
	     $result=Db::table("jf_integral")
		         ->update($data);
	  	if($result)
		  {$this->success("修改成功","Integral/integral");}
	    else 
		  {$this->error("修改失败");}
	  	}
  	else 
  	{
	  	$in_id=$request->param("in_id");
	  	$data=['in_id'=>$in_id];  
		$list=Db::name("jf_integral")
			  ->where('in_id',$in_id)
	          ->find();
	     return $this->fetch('jf_update',[
               'list'=>$list,
       ]);        
  	}
   }
   public function jf_delete()
   {
      $request=Request::instance();
      $in_id=$request->param('in_id');
      $data=['in_id'=>$in_id];
      $result=Db::table('jf_integral')->delete($data);
       if($result)
      {
        $this->success('删除成功','Integral/integral');  
      }
      else 
      {
        $this->error('删除失败');
      }
      
   }
}
